package com.hotel.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hotel.bean.Hotelinfor;
import com.hotel.service.HotelinService;
import com.hotel.service.impl.HotelinServiceImpl;
import com.hotel.util.BaseServlet;


//路遥
@WebServlet("/HotelinServlet")
public class HotelinServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       
	public String ui(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
		
		//根据id查询
		int hid = Integer.parseInt(request.getParameter("hid"));
		
		HotelinService hotelinService = new HotelinServiceImpl();
		Hotelinfor hotelinfor = hotelinService.qureyHotelById(hid);
		
		request.setAttribute("hotelinfor", hotelinfor);
		
		return "/user/goods.jsp";
	}
	
	//根据地名查询
	public String queryByArea(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
		
		String harea = request.getParameter("harea");
		
		HotelinService hotelinService = new HotelinServiceImpl();
		List<Hotelinfor> hotelinfor = hotelinService.queryByArea(harea);
		
		request.getSession().setAttribute("hotelinfor", hotelinfor);
		
		response.sendRedirect(request.getContextPath() + "/HotelinServlet?action=hotelinUi");
		
		return null;
	}

	//根据商品名称模糊查询
	public String queryByName(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {

		String hname = request.getParameter("hname");
		
		HotelinService hotelinService = new HotelinServiceImpl();
		List<Hotelinfor> hotelinfor = hotelinService.queryByName(hname);
		
		request.getSession().setAttribute("hotelinfor", hotelinfor);
		
		response.sendRedirect(request.getContextPath() + "/HotelinServlet?action=hotelinUi");
		
		return null;
	}
	
	//显示商品一览的ui
	public String hotelinUi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		return "/user/goods.jsp";
	}
	
	
	
}